package Main;

import Graphic.Background;
import Graphic.HUD;
import Handle.KeyInput;
import Handle.MouseInput;
import Window.Window;

import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.Menu;
import java.awt.image.BufferStrategy;

public class Game extends Canvas implements Runnable{
	
	public static final int WIDTH=600, HEIGHT =600;
	
	private Window frame = null;
	private Thread thread = null;
	
	private Background bg = null;
	private HUD hud = null;
	Menu menu = null;
	
	private KeyInput keyInput;
	private MouseInput mouseInput;
	/**
	 * @param args
	 */
	public Game ()
	{
		keyInput = new KeyInput();
		mouseInput = new MouseInput();
		
		frame = new Window(WIDTH + 2, HEIGHT + 2, "Space War", menu, this);
		frame.addKeyListener(keyInput);
		frame.addMouseMotionListener(mouseInput);
		
		this.addKeyListener(keyInput);
		this.addMouseMotionListener(mouseInput);
		
		bg = new Background();
		
		hud = new HUD(mouseInput);

	}

	public void run() {
		// TODO Auto-generated method stub
		
		while (true)
		{
			tick();
			render();
			
			
			try {
				thread.sleep(10);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}
	
	public synchronized void start()
	{
		if (thread != null)
				return;
		thread = new Thread(this);
		thread.start();
		
		
	}
	
	public void tick()
	{
		
	}
	public void render()
	{
		BufferStrategy bs = getBufferStrategy();
		
		if(bs == null)
		{
			createBufferStrategy(2);
			return;
		}
		Graphics g = bs.getDrawGraphics();
		
		//Background
		bg.render(g);
		
		
		
		
		
		
		//END - HUD
		hud.render(g);
		//END
		g.dispose();
		bs.show();
		bs.dispose();
	}
	// Main	///////////////////////////////////////////////
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Game();
	}

}//end class Game
